package cn.dcw.pethome.org.service.impl;

import cn.dcw.pethome.basic.util.PageList;
import cn.dcw.pethome.org.domain.Employee;
import cn.dcw.pethome.org.dto.EmployeeDto;
import cn.dcw.pethome.org.mapper.EmployeeMapper;
import cn.dcw.pethome.org.mapper.EmployeeMapper;
import cn.dcw.pethome.org.query.EmployeeQuery;
import cn.dcw.pethome.org.service.IEmployeeService;
import net.bytebuddy.implementation.bytecode.Throw;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/*
部门管理
 */
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)//添加事务
public class EmployeeServiceImpl implements IEmployeeService {
    //加载部门mapper
    @Autowired
    private EmployeeMapper mapper;
    @Autowired
    private EmployeeMapper employeeMapper;


    @Override
    @Transactional
    public void add(Employee employee) {
        mapper.add(employee);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Employee employee) {
        mapper.update(employee);
    }

    @Override
    public List<Employee> findAll() {
        return mapper.findAll();
    }


    //分页查询
    @Override
    public PageList<EmployeeDto> pageData(EmployeeQuery query) {
        System.out.println(query);
        //获取总条数
        Long totals = mapper.totals();
        System.out.println(totals);
        //查询部门的集合
        List<EmployeeDto> list = mapper.pageQuery(query);

        return new PageList<>(totals,list);//将查询的结果，封装到对象中
    }

    //批量删除
    @Override
    public void batchDel(Long[] ids) {
        mapper.batchDel(ids);
    }


}
